﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using nwrole.toolbox.sync;
using nwrole.toolbox.sync.ServiceHost;
using System.Threading;
using nwrole.toolbox.sync.service;

namespace sync_source_console
{
    class Program
    {

        static void myThread()
        {
            try
            {
                System.Console.WriteLine("Thread started...");

                while (true)
                {
                    try
                    {
                        System.Threading.Thread.Sleep(new TimeSpan(0, 0, 15));
                        SyncSourceService s = new SyncSourceService();
                        //s.InitParamService(new object[]{SyncSettings.SrcDbConnectionString, SyncSettings.DestDbConnectionString});
                     //   s.InitParamService(new SyncSrcServiceParams(SyncSettings.SrcDbConnectionString, SyncSettings.SyncDestinationConnInfo, DataProviderType.Sql));
                        s.SyncSyncEntity(10); // xn1 
                        s.SyncSyncEntity(11); // xn2
                        s.SyncSyncEntity(12); // xn3
                        s.SyncSyncEntity(2);  // ar
                        s.SyncSyncEntity(3);  // ars
                        s.SyncSyncEntity(1);  // fr
                        s.SyncSyncEntity(4);  // kpw
                        s.SyncSyncEntity(5);  // kus
                        s.SyncSyncEntity(8);  // prh
                        s.SyncSyncEntity(9);  // prl
                        s.SyncSyncEntity(7);  // oh
                        s.SyncSyncEntity(6);  // orp
                        s.SyncSyncEntity(13);  // fh
                        s.SyncSyncEntity(14);  // SyncEntityDelete
                        s.SyncSyncEntity(23);  // xen
                        System.Threading.Thread.Sleep(new TimeSpan(0, 1, 30));
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine(e.ToString());
                    }
                }

                //System.Console.ReadLine();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
            System.Console.WriteLine("");
            System.Console.WriteLine("");
            System.Console.WriteLine("Done.");
        }

        static void Main(string[] args)
        {
            try
            {
                SyncDestinationServiceHost destHost = new SyncDestinationServiceHost();
                //destHost.Open("http://localhost:9004/", "hejsan.svc", SyncSettings.DestDbConnectionString); // TODO: set connectionstring 120924, previously taken from ConnectionUtil
                destHost.Start(SyncSettings.SyncDestinationConnInfo, SyncSettings.DestDbConnectionString); // TODO: set connectionstring 120924, previously taken from ConnectionUtil

                /*Thread thread = new Thread(() => myThread());
                thread.Start();*/

                //ServiceConnectionInfo srcConnInfo = new ServiceConnectionInfo();

                SyncSourceServiceHost srcHost = new SyncSourceServiceHost();
                //srcHost.StartLocal("http://localhost:9004/", "hejsan.svc", SyncSettings.SrcDbConnectionString, SyncSettings.DestDbConnectionString);
                //srcHost.StartLocal(SyncSettings.LocalServiceBaseAddress, SyncSettings.LocalServiceAddress, SyncSettings.SrcDbConnectionString, SyncSettings.DestDbConnectionString, SyncSettings.SyncDestinationAddress);

                // srcHost.Start(SyncSettings.SyncSourceConnInfo, SyncSettings.SrcDbConnectionString, SyncSettings.SyncDestinationConnInfo, null, 1);


            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            System.Console.WriteLine("Started (press any key to exit)");
            System.Console.ReadKey();
            System.Console.WriteLine("Done.");
        }
    }
}
